<template>
	<view class="archives-base-box">
		<view class="head">
			<view class="tit">案卷基本信息</view>
			<!-- <u-button size="mini" type="default" @click="toTimeline">时间轴</u-button> -->
			<view class="btns">
				<button class="edit-btn" size="mini" type="default" @click="toEdit">编辑</button>
				<button size="mini" @click="telescopic">{{isExpand ? '展开':'收起' }}</button>
			</view>
		</view>
		<view class="content">
			<FormItem class="item max100" label="档案编号" :value="data.archivesId" />
			<FormItem class="item max100" label="起火对象" :value="data.fireName" />
			<FormItem class="item max100" label="起火地址" :value="formatAddress(data.fireAddress)" />
			<FormItem class="item max100" label="详细地址" :value="data.address || ''" />
			<FormItem class="item max100" label="起火天气" :value="data.weather" />
			<FormItem class="item max100" label="报警时间" :value="data.callTime" />
			<FormItem class="item max100" label="出警时间" :value="data.goTime" />
			<FormItem class="item max100" label="承办单位" :value="data.doOrg" />
			<FormItem class="item max100" label="承办人员" :value="(data.doPersonName || '') + (data.doOtherPersonName? ','+data.doOtherPersonName: '')" />
			<FormItem class="item" label="出警车辆" :value="data.doCars" />
			<FormItem class="item" label="出警人数" :value="data.doPersonCount" />
			<FormItem class="item" label="案件状态" :value="ARCHIVES_STATE_NAMES[data.state]" />
			<FormItem class="item" label="程序类型" :value="archivesTypeMap[data.archivesType]" />
			<view class="item max100">
				<view class="label color_333">简单描述</view>
				<view class="value color_999" :class="{'remark':isExpand}">{{ data.remark || '--' }}</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		checkType
	} from '@/common/utils/common.js'
	import {
		ARCHIVES_TYPE_NAMES,
		ARCHIVES_STATE_NAMES
	} from '@/const/archives'
	import FormItem from './FormItem.vue'
	export default {
		name: 'CaseInfoCard',
		components: {
			FormItem
		},
		props: {
			data: {
				type: Object,
				required: true
			},
		},
		data() {
			return {
				ARCHIVES_STATE_NAMES,
				archivesTypeMap: ARCHIVES_TYPE_NAMES,
				isExpand: true
			}
		},
		computed: {
			formatAddress() {
				return address => {
					if (!address || !address.length) return '--';
					if (checkType(address) === 'string') {
						return address.split(',')[2]
					} else if (checkType(address) === 'array') {
						return address[2];
					}
				};
			},
		},
		methods: {
			toEdit() {
				uni.navigateTo({
					url: `/pages/sys/archives/add?id=${this.data.archivesId}`
				});
			},
			telescopic() {
				this.isExpand = !this.isExpand
			}
		}
	}
</script>
<style scoped lang="scss">
	.archives-base-box {
		padding: 0 38rpx;

		.head {
			padding: 30rpx 0;
			border-bottom: 3rpx solid $u-border-color;
			display: flex;
			justify-content: space-between;
			align-items: center;


			uni-button {
				margin: 0;
			}

			.tit {
				display: flex;
				align-items: center;
				font-size: 36rpx;
				color: #333;
				font-weight: bold;
			}

			.edit-btn {
				margin-right: 32rpx;
			}
		}

		.content {
			display: flex;
			flex-wrap: wrap;
			padding-top: 16rpx;

			.item {
				flex: 1;
				min-width: 50%;
				font-size: 24rpx;

				&.max100 {
					min-width: 100%;
				}

				.label {
					font-weight: bold;
					margin-right: 10rpx;
				}

				.value {
					word-wrap: break-word;
					word-break: break-all;
				}
			}

			.remark {
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 3;
				overflow: hidden;
			}

			.btn {
				width: 100%;
				text-align: right;
			}
		}
	}
</style>